package main

import (
	"crypto/tls"
	"fmt"
	"github.com/dghubble/sling"
	"io"
	"net"
	"net/http"
	"time"
)
// ref: https://github.com/dghubble/sling
type Params struct {
	Count int `url:"count,omitempty"`
}
func main() {
	params := &Params{Count: 5}
	//req, err := sling.New().Get("http://dev.api.shanghaiguyi.cn/api/app/activate").QueryStruct(params).Request()
	//req, err := sling.New().Base("http://dev.api.shanghaiguyi.cn/").Path("api/").Path("app/activate").QueryStruct(params).Request()
	req, err := sling.New().Base("http://dev.api.shanghaiguyi.cn/").
		Set("cversion", "100").
		Path("api/").Path("app/activate").QueryStruct(params).Request()

	fmt.Println("===>",req.URL)

	if err != nil {
		return
	}
	tr := &http.Transport{
		Dial: (&net.Dialer{
			Timeout: 3 * time.Second,
		}).Dial,
		MaxIdleConns:    4,
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	// Create client
	client := &http.Client{Transport: tr, Timeout: time.Second * 5}
	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	respByte, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(respByte))
}
